﻿<?php
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = 'demandeConnexion';
}
$action = $_REQUEST['action'];
switch ($action) {
    case 'demandeConnexion': {
            include("vues/v_connexion.php");
            break;
        }
    case 'valideConnexion': {
            $login = $_REQUEST['login'];
            $mdp = $_REQUEST['password'];
            $admin = $pdo->getInfosAdmin($login, $mdp);

            if (!is_array($admin)) {
                ajouterErreur("Login ou mot de passe incorrect");
                include("vues/v_erreurs.php");
                include("vues/v_connexion.php");
            } else {
                $role = $pdo->getRoleAdmin($login, $mdp);
                $theme = $pdo->getThemeAdmin($login, $mdp);
                $id = $admin['id'];
                $nom = $admin['nom'];
                $prenom = $admin['prenom'];
                if ($role == "Operateur") {
                    $status = "Operateur";
                    connecter($id, $nom, $prenom, $status, $theme);
                    include("vues/v_menu_operateur.php");
                } elseif ($role == "Expert") {
                    $status = "Expert";
                    connecter($id, $nom, $prenom, $status, $theme);
                    include("vues/v_menu_expert.php");
                } elseif ($role == "Superviseur") {
                    $status = "Superviseur";
                    connecter($id, $nom, $prenom, $status, $theme);
                    include("vues/v_menu_superviseur.php");
                }
            }
            break;
        }
    case'deconnexion': {

            deconnecter();
        }
    default : {
            include("vues/v_connexion.php");
            break;
        }
}
        